package client.comm.baoding.dialog

import androidx.core.view.isVisible
import androidx.databinding.ObservableField
import androidx.fragment.app.FragmentActivity
import client.comm.commlib.utils.StoreUtil
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.DialogSelectpaytypeBinding
import client.tzstore.oo.dialog.BottomBindingDialog

/**
 * 支付方式 弹窗
 *
 * 1佣金支付
 * 2分享积分
 * 3支付宝支付
 *
 */
class SelectPayTypeDialog(context: FragmentActivity) :
    BottomBindingDialog<DialogSelectpaytypeBinding>(context) {

    override fun getV(): Int {
        return R.layout.dialog_selectpaytype
    }

    val income = ObservableField<String>("0")
    val integral = ObservableField<String>("0")
    val wallet_jin = ObservableField<String>("0")
    val wallet_pin = ObservableField<String>("0")
    val good_wallet_pin = ObservableField<Double>()

    override fun postBinding() {
        binding.event = this
        StoreUtil.getBean<UserInfo>(context)?.let {
            income.set("${it.income}")
            integral.set("${it.integral}")
//            wallet_jin.set("${it.integral_f}")
//            wallet_pin.set("${it.income_r}")

//            if (good_wallet_pin.get()!! > 0) {
//                binding.btnLpq.isVisible = true
//                binding.btnYue.isVisible = false
//                binding.btnAlipay.isVisible = false
////                binding.btnLjq.isVisible = false
//            } else {//普通商品，体验券隐藏
//                binding.btnYue.isVisible = true
//                binding.btnAlipay.isVisible = true
//                binding.btnLpq.isVisible = false
////                binding.btnLjq.isVisible = false
//            }
        }
    }

    var one: ((type: Int, txt: String) -> Unit)? = null

    fun oneType() {
        cancel()
        one?.invoke(1, "佣金支付(佣金:${income.get()}})")//,积分:${integral.get()
    }

    fun jfType() {
        cancel()
        one?.invoke(2, "积分支付(积分:${integral.get()})") //佣金:${income.get()},
    }

    fun shareLjqType() {
        cancel()
        one?.invoke(2, context.getString(R.string.wallet_jin) + "(${wallet_jin.get()})")
    }

    fun alipayType() {
        cancel()
        one?.invoke(3, "支付宝支付")
    }

    fun shareLpqType() {
        cancel()
        one?.invoke(4, context.getString(R.string.wallet_pin) + "(${wallet_pin.get()})")
    }

}